//
//  YYMineCell.m
//  Project
//
//  Created by Yown on 2024/2/5.
//

#import "YYMineCell.h"

#import <BIProjectModule/BIAppDefine.h>
#import <BIToolModule/NSString+Network.h>
#import <BIToolModule/BIProjectDefine.h>

#import <SDWebImage/SDWebImage.h>

@interface YYMineCell ()

@property (weak, nonatomic) IBOutlet UIView *cellView;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UIImageView *arrowImageView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelLeadingConstant;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *descLabelRightConstant;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *arrowImageWidthConstant;

@end

@implementation YYMineCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor clearColor];
    self.cellView.backgroundColor = [UIColor loadColorFromString:@"#FFFFFF"];
    self.cellView.layer.masksToBounds = YES;
    self.cellView.layer.cornerRadius = 16;
    
    self.titleLabel.textColor = [UIColor loadColorFromString:@"#333333"];
    self.titleLabel.font = BIFont(16);
    
    self.descLabel.textColor = [UIColor loadColorFromString:@"#828282"];
    self.descLabel.font = BIFont(16);
}

- (void)setupModel:(YYMineCellModel *)model {
    self.titleLabel.text = BILocalizedString(model.title);
    self.descLabel.text = BILocalizedString(model.desc);
    
    if (model.iconName.length > 0) {
        self.iconImageView.image = [UIImage imageNamed:model.iconName];
        self.titleLabelLeadingConstant.constant = 8;
    } else {
        self.iconImageView.image = nil;
        self.titleLabelLeadingConstant.constant = -20;
    }
    
    if (model.arrowName.length > 0) {
        if ([NSString isURL:model.arrowName]) {
            [self.arrowImageView sd_setImageWithURL:[NSURL URLWithString:model.arrowName] placeholderImage:[UIImage imageNamed:@"mine_avatar_placeholder"]];
        } else {
            self.arrowImageView.image = [UIImage imageNamed:model.arrowName];
        }
        self.descLabelRightConstant.constant = -8;
    } else {
        self.arrowImageView.image = nil;
        self.descLabelRightConstant.constant = -20;
    }
}

- (void)adjustArrowWidth:(CGFloat)width {
    self.arrowImageWidthConstant.constant = width;
}

+ (CGFloat)cellHeight {
    return 80;
}

@end

